<?php
/**
 * @package panel
 * @subpackage panel.settings
**/
/**
 * Panel Environment settings
 * @author Dmitry Bakaleinik (code)
 */
abstract class panel__settings__environment {

	static public function getRancidCommand() {

		return "/opt/rancid/rancid {ip} {command} {vendor}";

	}	# Function

	const STATE__LOCAL      = "local";
	const STATE__TESTING    = "testing";
	const STATE__PRODUCTION = "production";

	static public function getState() {

		if( ($state = self::getConfig("panel.state")) ) {
			return $state; }

		return self::STATE__LOCAL;
		//return self::STATE__TESTING;
		//return self::STATE__PRODUCTION;

	}	# Function

	static public function isDebug()         { return (self::getState() == self::STATE__LOCAL); }
	static public function isOnCLI()         { return (PHP_SAPI === "cli"); }
	static public function isStrict()        { return FALSE; }
	static public function isLogQuerires()   { return TRUE; }
	static public function isOnLamp()        { return file_exists("/opt/lamp"); }
	static public function isUseGZIPOutput() { return !self::isVerbose() && !self::isDebug(); }
	static public function isUseCache()      { return FALSE || isset_or($_REQUEST["_cache"]); }
	static public function isACLDisabled()   { return (self::getState() != self::STATE__PRODUCTION); }
	static public function getVersion()      { return "0.1";  }
	static public function getCombinedID()   { return ""; }

	static public function isVerbose($_key_ = NULL) {

		$R = FALSE;

		$verbose = array(

			"panel.application.request.decodeB64Json"    => FALSE,
			"panel.application.response.response_length" => FALSE,
			"panel.application.process.statistics"       => TRUE,

			"panel.environment.cache.xcache.id"          => FALSE,
			"panel.environment.cache.cache_object_class" => FALSE,

			"panel.rrp.majax.execution_time"             => FALSE,

			"panel.db.log_direct_queries"                => FALSE,
			"panel.db.explain_queries"                   => FALSE,
			"panel.db.explain_queries.trigger_time"      => 3,
			"panel.db.explain_queries.trigger_rows"      => 10,
			"panel.db.explain_queries.trigger_diff_join_size" => TRUE,

		);

		if( isset_or($_REQUEST["_verbose"]) ) {
			$R = TRUE; }

		if( $R && $_key_ ) {

			return isset_or($verbose[$_key_], FALSE);

		} else {

			return $R;

		}	# if

	}	# Function

	static public function getConfig($_option_ = NULL) {

		static $config;

		if( !is_array($config) ) {

			$ini    = new maf__fso__file(PANEL__PATH__SETTINGS . "/config.ini");
			$config = array();

			if( $ini->isExists() ) {

				$config = parse_ini_file($ini->getPath(), TRUE);

			}	# if

			if( !is_array($config) ) {
				$config = array(); }

		}	# if

		if($_option_) {

			return isset_or($config[$_option_]);

		} else {

			return $config;

		}	# if

	}	# Function

	static public function isLocked() {

		if( !file_exists(PANEL__PATH . "/panel.lock") ) {
			return FALSE; }

		try {

			return trim( file_get_contents(PANEL__PATH . "/panel.lock") );

		} catch( exception $e ) {

			panel__logger__errors::getInstance()->logException($e);
			return TRUE;

		}

	}	# Function

	static public function getPHP() {

		if( ($php = self::getConfig("panel.path_php")) ) {
			return $php; }

		switch( TRUE ) {

		case panel__settings__environment::isOnLamp():
		case self::getState() == self::STATE__PRODUCTION:
		case self::getState() == self::STATE__TESTING:
		case self::getState() == self::STATE__LOCAL:
		default:
			return "/usr/bin/php";
			break;

		}	# switch

	}	# Function

}	# Class

/* EOF */